package main

import (
	"fmt"
	"github.com/jinzhu/now"
	"time"
)

func main() {
	//dingo.InitViper("./configs/adm.yaml")
	//dbs.NewMysqlComponent().Step()

	//logic.NewSyncLogic().DotaskUsers(1,"/Volumes/zhang/dev-zhongman/yunman-api/data/users/sc_user_20210628152706")
	//
	//logic.NewSyncLogic().DotaskPlaceRules(10, 20000, "/Volumes/zhang/dev-zhongman/记录/任务/易充迁移数据/网点价格表.json")
	//logic.NewSyncLogic().DotaskPlaceRules(12, 20000, "/Volumes/zhang/dev-zhongman/记录/任务/易充迁移数据/网点价格-套餐.json")
	//logic.NewSyncLogic().DotaskPlaceRules(10, 30000, "/Volumes/zhang/dev-zhongman/记录/任务/中曼迁移数据/网点价格.json")
	//logic.NewSyncLogic().DotaskPlaceRules(12, 30000, "/Volumes/zhang/dev-zhongman/记录/任务/中曼迁移数据/网点价格-套餐.json")

	//logic.NewSyncLogic().DotaskRemoveUser()
	//logic.NewSyncLogic().DotaskRemoveUserUpdate(1)

	//code := "002345"
	//fmt.Println(code[0:1], code[1:], "8"+code[1:])
	//
	//amount := int64(1000)
	//amount -= int64(float64(amount)*float64(2)/100)
	//fmt.Println(amount)

	fmt.Println(AddDate(time.Now(), 0, 1))
}

func AddDate(t time.Time, years int, months int) time.Time {
	year, month, day := t.Date()
	hour, min, sec := t.Clock()

	firstDayOfMonthAfterAddDate := time.Date(year+years, month+time.Month(months), 1,
		hour, min, sec, t.Nanosecond(), t.Location())
	lastDay := now.New(firstDayOfMonthAfterAddDate).EndOfMonth().Day()

	if day > lastDay {
		day = lastDay
	}

	return time.Date(year+years, month+time.Month(months), day,
		hour, min, sec, t.Nanosecond(), t.Location())
}
